package com.lifang.framework.util;

import cn.hutool.core.util.StrUtil;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class AnnotationUtils {

    public static Object getValue(Annotation annotation, String attributeName) {
        if (annotation == null || StrUtil.isBlank(attributeName)) {
            return null;
        }
        try {
            Method method = annotation.getClass().getDeclaredMethod(attributeName);
            if (Modifier.isPrivate(method.getModifiers())) {
                method.setAccessible(Boolean.TRUE);
            }
            return method.invoke(annotation);
        } catch (Exception ex) {
            return null;
        }
    }

}
